
 const BASE_URL = 'http://192.168.2.103:3000'
 // const BASE_URL = 'http://192.168.2.105:8080'
 // const BASE_URL = 'http://192.168.2.101:8080'
 // const BASE_URL = '/api'
 
 export default function(url, data, config ={
	 method: 'get',
	 showLoading: true,
 }){
	return new Promise((resolve, reject)=> {
		if(!url){
			reject('没有url')
		}
		if(config.showLoading){
			uni.showLoading({
				title: '加载中...',
			})
		}
		const token = uni.getStorageSync('token') || ''
		uni.request({
			url: BASE_URL  + url,
			 header: {
				 token: token
			 },
			 method: config.method || 'get',
			 data: data,
			 success(res) {
				if(res.data.code == 200){
					resolve(res.data.data?res.data.data:res.data)
				}else{
					uni.showToast({
						title: res.data.msg,
						icon: 'none'
					})
					reject(res.data.msg)
				}
			 },
			 fail(err) {
				 uni.showToast({
				 	title: err,
					icon: 'none'
				 })
			 	reject(err)
			 },
			 complete() {
			 	uni.hideLoading()
			 }
		})
	})
 }